package list

import (
	"strings"

	"gitee.com/linxing_3/sr-core/yal/ystr"
	"gitee.com/mkwchecking/sr-admin/cmd"
	"gitee.com/mkwchecking/sr-admin/cmd/domain"
	"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
	Use:   "list",
	Short: "list commands to print registed apps",
	Run:   printAppList,
}

func init() {
	cmd.RootCmd().AddCommand(listCmd)
}

func printAppList(cmd *cobra.Command, args []string) {
	apps := domain.GetDomainsInject()
	cmd.Println("\n\nRegisted apps: \n\r",
		ystr.PadRight("Name", " ", 20),
		"|",
		ystr.PadRight("Description", " ", 20),
	)
	cmd.Println(strings.Repeat("-", 41))
	for _, app := range apps {
		cmd.Println(
			ystr.PadRight(app.Name, " ", 20),
			"|",
			ystr.PadRight(app.Description, " ", 20),
		)
	}
}
